Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 863)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.03687 13.03260 13.02838 13.02420 13.02007 13.01598 13.01194 13.00795
## [9] 13.00401 13.00011 12.99626 12.99245 12.98869 12.98498 12.98131 12.97769
## [17] 12.97412 12.97059 12.96711 12.96367 12.96028 12.95694 12.95364 12.95039
## [25] 12.94718 12.94402 12.94091 12.93784 12.93482 12.93184 12.92891 12.92602
## [33] 12.92318 12.92039 12.91764 12.91493 12.91227 12.90966 12.90709 12.90456
## [41] 12.90209 12.89965 12.89726 12.89493 12.89267 12.89047 12.88835 12.88629
## [49] 12.88429 12.88236 12.88050 12.87870 12.87696 12.87528 12.87367 12.87212
## [57] 12.87063 12.86920 12.86782 12.86651 12.86525 12.86405 12.86291 12.86182
## [65] 12.86079 12.85981 12.85889 12.85802 12.85720 12.85643 12.85571 12.85505
## [73] 12.85443 12.85386 12.85334 12.85287 12.85244 12.85206 12.85173 12.85144
## [81] 12.85120 12.85099 12.85083 12.85071 12.85064 12.85060 12.85061 12.85065
## [89] 12.85073 12.85085 12.85101 12.85120 12.85145 12.85179 12.85222 12.85272
## [97] 12.85331 12.85397 12.85471 12.85551 12.85639 12.85734 12.85835 12.85943
## [105] 12.86057 12.86176 12.86302 12.86432 12.86569 12.86710 12.86855 12.87006
## [113] 12.87161 12.87319 12.87482 12.87649 12.87819 12.87992 12.88168 12.88347
## [121] 12.88528 12.88712 12.88898 12.89086 12.89275 12.89466 12.89658 12.89851
## [129] 12.90045 12.90240 12.90434 12.90629 12.90824 12.91018 12.91212 12.91478
## [137] 12.91881 12.92410 12.93053 12.93799 12.94637 12.95555 12.96541 12.97586
## [145] 12.98676 12.99801 13.00949 13.02109 13.03270 13.04419 13.05547 13.06641
## [153] 13.07689 13.08682 13.09606 13.10451 13.11206 13.11858 13.12397 13.12812
## [161] 13.13090 13.13336 13.13657 13.14047 13.14501 13.15012 13.15575 13.16185
## [169] 13.16834 13.17518 13.18230 13.18965 13.19716 13.20479 13.21247 13.22014
## [177] 13.22775 13.23523 13.24253 13.24960 13.25637 13.26278 13.26877 13.27430
## [185] 13.27929 13.28369 13.28745 13.29050 13.29279 13.29425 13.29484 13.29448
## [193] 13.29313 13.29073 13.28721 13.28251 13.27646 13.26897 13.26015 13.25011
## [201] 13.23896 13.22680 13.21373 13.19988 13.18535 13.17024 13.15466 13.13872
## [209] 13.12253 13.10619 13.08982 13.07352 13.05740 13.04156 13.02612 13.01118
## [217] 12.99685 12.98324 12.97045 12.95698 12.94134 12.92372 12.90426 12.88316
## [225] 12.86056 12.83664 12.81156 12.78550 12.75862 12.73108 12.70307 12.67473
## [233] 12.64625 12.61779 12.58951 12.56159 12.53419 12.50749 12.48163 12.45681
## [241] 12.43317 12.41090 12.39015 12.37110 12.35391 12.33758 12.32102 12.30427
## [249] 12.28736 12.27033 12.25321 12.23606 12.21889 12.20175 12.18468 12.16771
## [257] 12.15087 12.13422 12.11778 12.10159 12.08569 12.07011 12.05490 12.04008
## [265] 12.02571 12.01180 11.99881 11.98706 11.97647 11.96692 11.95832 11.95055
## [273] 11.94353 11.93714 11.93129 11.92587 11.92077 11.91591 11.91116 11.90644
## [281] 11.90163 11.89664 11.89136 11.88570 11.87954 11.87278 11.86533 11.85708
## [289] 11.84793 11.83815 11.82812 11.81786 11.80743 11.79684 11.78613 11.77534
## [297] 11.76451 11.75366 11.74283 11.73205 11.72137 11.71081 11.70040 11.69019
## [305] 11.68021 11.67049 11.66106 11.65196 11.64323 11.63489 11.62699 11.61955
## [313] 11.61262 11.60622 11.60039 11.59413 11.58654 11.57777 11.56797 11.55731
## [321] 11.54594 11.53401 11.52170 11.50914 11.49651 11.48396 11.47164 11.45972
## [329] 11.44835 11.43769 11.42789 11.41912 11.41153 11.40528 11.40052 11.39742
## [337] 11.39613 11.39680 11.39860 11.40059 11.40277 11.40518 11.40784 11.41075
## [345] 11.41395 11.41744 11.42125 11.42540 11.42991 11.43479 11.44007 11.44576
## [353] 11.45189 11.45847 11.46551 11.47305 11.48110 11.48968 11.49880 11.50849
## [361] 11.51877 11.52965 11.54116 11.55331 11.56741 11.58462 11.60470 11.62742
## [369] 11.65256 11.67989 11.70917 11.74018 11.77269 11.80646 11.84128 11.87690
## [377] 11.91311 11.94966 11.98634 12.02291 12.05915 12.09482 12.12969 12.16354
## [385] 12.19614 12.22725 12.25665 12.28411 12.30940 12.33229 12.35255 12.36996
## [393] 12.38672 12.40511 12.42493 12.44598 12.46810 12.49109 12.51476 12.53893
## [401] 12.56340 12.58801 12.61255 12.63683 12.66069 12.68392 12.70634 12.72776
## [409] 12.74801 12.76688 12.78420 12.79977 12.81341 12.82494 12.83417 12.84146
## [417] 12.84737 12.85198 12.85537 12.85761 12.85879 12.85899 12.85828 12.85675
## [425] 12.85448 12.85154 12.84801 12.84397 12.83951 12.83471 12.82963 12.82437
## [433] 12.81900 12.81360 12.80826 12.80304 12.79803 12.79332 12.78897 12.78507
## [441] 12.78170 12.77724 12.77016 12.76075 12.74925 12.73592 12.72103 12.70484
## [449] 12.68760 12.66958 12.65104 12.63223 12.61342 12.59487 12.57683 12.55958
## [457] 12.54335 12.52843 12.51507 12.50352 12.49405 12.48692 12.48000 12.47115
## [465] 12.46055 12.44841 12.43492 12.42030 12.40472 12.38840 12.37154 12.35433
## [473] 12.33697 12.31967 12.30261 12.28601 12.27006 12.25496 12.24091 12.22811
## [481] 12.21675 12.20705 12.19919 12.19338 12.18981 12.18804 12.18741 12.18786
## [489] 12.18931 12.19169 12.19491 12.19891 12.20360 12.20892 12.21479 12.22113
## [497] 12.22787 12.23492 12.24223 12.24971 12.25728 12.26487 12.27241 12.27981
## [505] 12.28701 12.29394 12.30050 12.30663 12.31226 12.31730 12.32169 12.32691
## [513] 12.33439 12.34394 12.35538 12.36853 12.38319 12.39918 12.41632 12.43443
## [521] 12.45331 12.47279 12.49268 12.51279 12.53293 12.55294 12.57261 12.59176
## [529] 12.61021 12.62778 12.64428 12.65952 12.67332 12.68550 12.69586 12.70424
## [537] 12.71043 12.71425 12.71553 12.71515 12.71415 12.71256 12.71040 12.70768
## [545] 12.70444 12.70069 12.69645 12.69176 12.68662 12.68107 12.67513 12.66881
## [553] 12.66214 12.65514 12.64784 12.64026 12.63241 12.62433 12.61603 12.60754
## [561] 12.59887 12.59006 12.58112 12.57207 12.56295 12.55376 12.54454 12.53530
## [569] 12.52607 12.51564 12.50294 12.48813 12.47142 12.45299 12.43302 12.41171
## [577] 12.38924 12.36579 12.34157 12.31674 12.29151 12.26606 12.24057 12.21523
## [585] 12.19024 12.16577 12.14202 12.11918 12.09742 12.07694 12.05793 12.04057
## [593] 12.02505 12.01156 12.00028 11.98905 11.97573 11.96054 11.94369 11.92541
## [601] 11.90592 11.88544 11.86419 11.84239 11.82026 11.79802 11.77589 11.75410
## [609] 11.73286 11.71239 11.69292 11.67467 11.65785 11.64269 11.62940 11.61822
## [617] 11.60935 11.60303 11.59873 11.59577 11.59406 11.59354 11.59414 11.59578
## [625] 11.59839 11.60190 11.60624 11.61134 11.61712 11.62351 11.63045 11.63786
## [633] 11.64567 11.65380 11.66220 11.67077 11.67946 11.68819 11.69688 11.70548
## [641] 11.71390 11.72207 11.72993 11.73740 11.74603 11.75726 11.77083 11.78651
## [649] 11.80403 11.82315 11.84361 11.86518 11.88760 11.91062 11.93399 11.95746
## [657] 11.98079 12.00372 12.02600 12.04739 12.06763 12.08647 12.10368 12.11898
## [665] 12.13215 12.14462 12.15797 12.17212 12.18699 12.20252 12.21862 12.23523
## [673] 12.25227 12.26966 12.28734 12.30522 12.32324 12.34132 12.35938 12.37735
## [681] 12.39516 12.41274 12.43000 12.44688 12.46329 12.47918 12.49446 12.50905
## [689] 12.52290 12.53591 12.54802 12.55915 12.56922 12.57852 12.58737 12.59581
## [697] 12.60385 12.61153 12.61887 12.62590 12.63264 12.63912 12.64536 12.65139
## [705] 12.65725 12.66294 12.66851 12.67397 12.67935 12.68468 12.68999 12.69530
## [713] 12.70063 12.70601 12.71148 12.71704 12.72252 12.72769 12.73258 12.73719
## [721] 12.74155 12.74566 12.74955 12.75322 12.75670 12.75999 12.76311 12.76608
## [729] 12.76891 12.77161 12.77421 12.77671 12.77912 12.78148 12.78378 12.78604
## [737] 12.78829 12.79053 12.79277 12.79504 12.79735 12.79970 12.80194 12.80389
## [745] 12.80556 12.80697 12.80813 12.80908 12.80981 12.81035 12.81071 12.81092
## [753] 12.81098 12.81091 12.81074 12.81047 12.81012 12.80972 12.80927 12.80879
## [761] 12.80830 12.80782 12.80736 12.80694 12.80657 12.80610 12.80538 12.80442
## [769] 12.80325 12.80187 12.80030 12.79857 12.79668 12.79467 12.79254 12.79031
## [777] 12.78800 12.78563 12.78321 12.78076 12.77831 12.77586 12.77343 12.77105
## [785] 12.76872 12.76647 12.76432 12.76227 12.76035 12.75858 12.75698 12.75543
## [793] 12.75384 12.75219 12.75050 12.74876 12.74698 12.74515 12.74328 12.74137
## [801] 12.73941 12.73742 12.73538 12.73331 12.73121 12.72907 12.72689 12.72469
## [809] 12.72245 12.72018 12.71788 12.71556 12.71320 12.71083 12.70842 12.70600
## [817] 12.70355 12.70108 12.69860 12.69608 12.69352 12.69092 12.68829 12.68561
## [825] 12.68290 12.68015 12.67737 12.67455 12.67169 12.66880 12.66588 12.66292
## [833] 12.65993 12.65691 12.65385 12.65076 12.64765 12.64450 12.64133 12.63812
## [841] 12.63489 12.63163 12.62835 12.62505 12.62174 12.61841 12.61507 12.61170
## [849] 12.60832 12.60491 12.60148 12.59802 12.59454 12.59104 12.58750 12.58394
## [857] 12.58034 12.57672 12.57306 12.56937 12.56564 12.56188 12.55808
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 863)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.58198 12.57903 12.57615 12.57333 12.57057 12.56787 12.56524 12.56267
## [9] 12.56016 12.55772 12.55534 12.55303 12.55078 12.54860 12.54649 12.54444
## [17] 12.54246 12.54055 12.53871 12.53693 12.53522 12.53359 12.53202 12.53052
## [25] 12.52910 12.52774 12.52646 12.52524 12.52410 12.52304 12.52204 12.52112
## [33] 12.52027 12.51950 12.51880 12.51818 12.51763 12.51716 12.51676 12.51644
## [41] 12.51620 12.51603 12.51595 12.51595 12.51605 12.51625 12.51655 12.51695
## [49] 12.51744 12.51802 12.51870 12.51946 12.52032 12.52126 12.52229 12.52340
## [57] 12.52460 12.52588 12.52724 12.52868 12.53019 12.53179 12.53346 12.53520
## [65] 12.53701 12.53890 12.54085 12.54288 12.54497 12.54712 12.54934 12.55162
## [73] 12.55396 12.55636 12.55882 12.56134 12.56391 12.56654 12.56922 12.57195
## [81] 12.57473 12.57756 12.58043 12.58336 12.58632 12.58933 12.59238 12.59547
## [89] 12.59860 12.60176 12.60496 12.60820 12.61162 12.61536 12.61940 12.62374
## [97] 12.62836 12.63323 12.63836 12.64371 12.64929 12.65507 12.66103 12.66717
## [105] 12.67347 12.67992 12.68649 12.69318 12.69997 12.70684 12.71379 12.72079
## [113] 12.72783 12.73490 12.74198 12.74906 12.75612 12.76314 12.77012 12.77704
## [121] 12.78388 12.79063 12.79728 12.80380 12.81019 12.81643 12.82250 12.82839
## [129] 12.83409 12.83958 12.84484 12.84987 12.85464 12.85979 12.86588 12.87283
## [137] 12.88052 12.88887 12.89779 12.90716 12.91690 12.92691 12.93709 12.94734
## [145] 12.95758 12.96769 12.97759 12.98718 12.99636 13.00503 13.01310 13.02047
## [153] 13.02704 13.03273 13.03742 13.04102 13.04463 13.04936 13.05512 13.06183
## [161] 13.06940 13.07776 13.08681 13.09647 13.10666 13.11729 13.12828 13.13955
## [169] 13.15101 13.16258 13.17418 13.18571 13.19710 13.20827 13.21912 13.22957
## [177] 13.23955 13.24897 13.25773 13.26577 13.27299 13.27931 13.28465 13.28892
## [185] 13.29204 13.29392 13.29449 13.29365 13.29132 13.28725 13.28130 13.27360
## [193] 13.26427 13.25342 13.24118 13.22767 13.21300 13.19729 13.18068 13.16326
## [201] 13.14518 13.12654 13.10746 13.08808 13.06849 13.04884 13.02922 13.00978
## [209] 12.99062 12.97186 12.95363 12.93604 12.91922 12.90329 12.88836 12.87455
## [217] 12.86199 12.84886 12.83339 12.81581 12.79634 12.77517 12.75255 12.72866
## [225] 12.70375 12.67801 12.65166 12.62493 12.59802 12.57115 12.54454 12.51840
## [233] 12.49295 12.46840 12.44497 12.42288 12.40233 12.38355 12.36675 12.35215
## [241] 12.33891 12.32605 12.31355 12.30138 12.28954 12.27800 12.26673 12.25573
## [249] 12.24497 12.23443 12.22409 12.21394 12.20395 12.19411 12.18439 12.17478
## [257] 12.16525 12.15579 12.14638 12.13700 12.12762 12.11824 12.10883 12.09936
## [265] 12.08983 12.08021 12.07135 12.06401 12.05805 12.05335 12.04977 12.04718
## [273] 12.04543 12.04441 12.04396 12.04397 12.04429 12.04480 12.04535 12.04582
## [281] 12.04606 12.04595 12.04536 12.04414 12.04216 12.03929 12.03540 12.03035
## [289] 12.02401 12.01686 12.00949 12.00192 11.99417 11.98627 11.97824 11.97009
## [297] 11.96186 11.95357 11.94524 11.93688 11.92853 11.92021 11.91193 11.90373
## [305] 11.89561 11.88762 11.87976 11.87206 11.86455 11.85724 11.85016 11.84332
## [313] 11.83677 11.83051 11.82456 11.81763 11.80856 11.79755 11.78486 11.77069
## [321] 11.75527 11.73885 11.72163 11.70384 11.68573 11.66750 11.64939 11.63162
## [329] 11.61442 11.59802 11.58264 11.56851 11.55586 11.54492 11.53590 11.52904
## [337] 11.52457 11.52271 11.52229 11.52203 11.52194 11.52205 11.52237 11.52293
## [345] 11.52374 11.52484 11.52624 11.52797 11.53004 11.53248 11.53530 11.53853
## [353] 11.54220 11.54632 11.55091 11.55600 11.56160 11.56775 11.57445 11.58174
## [361] 11.58963 11.59814 11.60730 11.61713 11.62873 11.64306 11.65993 11.67914
## [369] 11.70049 11.72378 11.74883 11.77543 11.80339 11.83250 11.86258 11.89343
## [377] 11.92486 11.95665 11.98863 12.02059 12.05234 12.08367 12.11440 12.14433
## [385] 12.17326 12.20099 12.22733 12.25208 12.27505 12.29604 12.31485 12.33129
## [393] 12.34762 12.36612 12.38652 12.40862 12.43217 12.45693 12.48269 12.50919
## [401] 12.53622 12.56353 12.59090 12.61808 12.64485 12.67098 12.69623 12.72036
## [409] 12.74315 12.76435 12.78375 12.80110 12.81617 12.82873 12.83854 12.84641
## [417] 12.85329 12.85924 12.86430 12.86850 12.87190 12.87453 12.87645 12.87768
## [425] 12.87827 12.87826 12.87771 12.87664 12.87510 12.87314 12.87079 12.86810
## [433] 12.86511 12.86187 12.85841 12.85477 12.85101 12.84716 12.84326 12.83937
## [441] 12.83551 12.82989 12.82090 12.80889 12.79420 12.77718 12.75816 12.73750
## [449] 12.71552 12.69259 12.66904 12.64521 12.62144 12.59809 12.57549 12.55399
## [457] 12.53392 12.51564 12.49949 12.48580 12.47493 12.46722 12.46008 12.45087
## [465] 12.43980 12.42709 12.41295 12.39760 12.38126 12.36413 12.34645 12.32842
## [473] 12.31026 12.29220 12.27443 12.25719 12.24068 12.22513 12.21075 12.19776
## [481] 12.18637 12.17680 12.16926 12.16398 12.16117 12.16008 12.15981 12.16030
## [489] 12.16152 12.16342 12.16596 12.16909 12.17279 12.17699 12.18167 12.18677
## [497] 12.19226 12.19809 12.20422 12.21061 12.21721 12.22399 12.23089 12.23789
## [505] 12.24493 12.25197 12.25897 12.26590 12.27269 12.27932 12.28574 12.29366
## [513] 12.30466 12.31850 12.33493 12.35371 12.37461 12.39736 12.42175 12.44751
## [521] 12.47441 12.50221 12.53066 12.55952 12.58854 12.61750 12.64613 12.67421
## [529] 12.70148 12.72771 12.75265 12.77605 12.79769 12.81731 12.83467 12.84953
## [537] 12.86164 12.87077 12.87667 12.88088 12.88508 12.88924 12.89333 12.89731
## [545] 12.90116 12.90484 12.90832 12.91158 12.91458 12.91729 12.91969 12.92173
## [553] 12.92338 12.92463 12.92543 12.92576 12.92558 12.92486 12.92357 12.92169
## [561] 12.91918 12.91600 12.91214 12.90755 12.90220 12.89608 12.88913 12.88135
## [569] 12.87268 12.86191 12.84800 12.83120 12.81176 12.78992 12.76593 12.74004
## [577] 12.71249 12.68353 12.65342 12.62239 12.59069 12.55858 12.52629 12.49408
## [585] 12.46219 12.43088 12.40038 12.37095 12.34282 12.31626 12.29151 12.26881
## [593] 12.24841 12.23056 12.21551 12.20043 12.18254 12.16211 12.13945 12.11484
## [601] 12.08857 12.06092 12.03220 12.00268 11.97266 11.94242 11.91226 11.88247
## [609] 11.85333 11.82513 11.79817 11.77273 11.74910 11.72757 11.70844 11.69198
## [617] 11.67849 11.66826 11.66020 11.65302 11.64669 11.64117 11.63645 11.63249
## [625] 11.62927 11.62676 11.62492 11.62375 11.62319 11.62324 11.62385 11.62501
## [633] 11.62668 11.62883 11.63145 11.63450 11.63795 11.64177 11.64594 11.65044
## [641] 11.65522 11.66027 11.66555 11.67105 11.67824 11.68844 11.70139 11.71679
## [649] 11.73436 11.75384 11.77493 11.79736 11.82085 11.84513 11.86990 11.89489
## [657] 11.91982 11.94442 11.96839 11.99147 12.01337 12.03382 12.05253 12.06922
## [665] 12.08362 12.09752 12.11284 12.12946 12.14727 12.16617 12.18605 12.20680
## [673] 12.22831 12.25047 12.27318 12.29631 12.31978 12.34346 12.36725 12.39103
## [681] 12.41471 12.43817 12.46130 12.48400 12.50615 12.52764 12.54838 12.56824
## [689] 12.58713 12.60492 12.62152 12.63681 12.65069 12.66373 12.67658 12.68926
## [697] 12.70175 12.71405 12.72618 12.73812 12.74988 12.76146 12.77286 12.78407
## [705] 12.79511 12.80596 12.81664 12.82713 12.83744 12.84758 12.85754 12.86731
## [713] 12.87691 12.88633 12.89558 12.90464 12.91355 12.92231 12.93093 12.93939
## [721] 12.94770 12.95584 12.96382 12.97162 12.97926 12.98671 12.99397 13.00105
## [729] 13.00794 13.01462 13.02110 13.02738 13.03344 13.03929 13.04491 13.05031
## [737] 13.05548 13.06041 13.06510 13.06955 13.07375 13.07769 13.08140 13.08490
## [745] 13.08817 13.09124 13.09409 13.09674 13.09918 13.10141 13.10344 13.10527
## [753] 13.10690 13.10833 13.10957 13.11062 13.11147 13.11213 13.11261 13.11290
## [761] 13.11301 13.11294 13.11268 13.11225 13.11164 13.11060 13.10890 13.10658
## [769] 13.10369 13.10030 13.09643 13.09215 13.08750 13.08253 13.07729 13.07183
## [777] 13.06620 13.06044 13.05462 13.04877 13.04295 13.03720 13.03157 13.02612
## [785] 13.02089 13.01593 13.01129 13.00703 13.00318 12.99980 12.99694 12.99427
## [793] 12.99146 12.98851 12.98543 12.98222 12.97890 12.97547 12.97194 12.96832
## [801] 12.96461 12.96083 12.95698 12.95307 12.94910 12.94509 12.94105 12.93697
## [809] 12.93287 12.92876 12.92464 12.92053 12.91642 12.91234 12.90827 12.90424
## [817] 12.90026 12.89632 12.89244 12.88855 12.88460 12.88058 12.87650 12.87236
## [825] 12.86817 12.86393 12.85965 12.85532 12.85095 12.84655 12.84212 12.83766
## [833] 12.83317 12.82867 12.82415 12.81962 12.81508 12.81054 12.80599 12.80145
## [841] 12.79692 12.79239 12.78791 12.78349 12.77913 12.77483 12.77057 12.76635
## [849] 12.76216 12.75800 12.75387 12.74975 12.74563 12.74152 12.73741 12.73328
## [857] 12.72914 12.72498 12.72079 12.71656 12.71229 12.70797 12.70360
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 863)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.03022 12.02425 12.01836 12.01256 12.00685 12.00122 11.99569 11.99025
## [9] 11.98489 11.97963 11.97445 11.96936 11.96436 11.95945 11.95463 11.94990
## [17] 11.94525 11.94069 11.93622 11.93184 11.92755 11.92335 11.91923 11.91520
## [25] 11.91126 11.90741 11.90365 11.89997 11.89638 11.89288 11.88947 11.88614
## [33] 11.88291 11.87976 11.87669 11.87372 11.87083 11.86803 11.86531 11.86269
## [41] 11.86015 11.85770 11.85533 11.85305 11.85086 11.84876 11.84674 11.84481
## [49] 11.84296 11.84120 11.83956 11.83804 11.83666 11.83541 11.83428 11.83329
## [57] 11.83241 11.83166 11.83103 11.83052 11.83012 11.82984 11.82968 11.82962
## [65] 11.82968 11.82984 11.83011 11.83048 11.83095 11.83153 11.83220 11.83298
## [73] 11.83384 11.83480 11.83585 11.83699 11.83822 11.83953 11.84093 11.84241
## [81] 11.84397 11.84561 11.84733 11.84912 11.85098 11.85292 11.85493 11.85700
## [89] 11.85914 11.86134 11.86360 11.86593 11.86831 11.87075 11.87324 11.87579
## [97] 11.87839 11.88104 11.88373 11.88652 11.88945 11.89251 11.89571 11.89903
## [105] 11.90249 11.90608 11.90979 11.91363 11.91759 11.92167 11.92587 11.93018
## [113] 11.93461 11.93915 11.94381 11.94857 11.95344 11.95842 11.96349 11.96868
## [121] 11.97395 11.97933 11.98480 11.99037 11.99603 12.00178 12.00761 12.01354
## [129] 12.01954 12.02563 12.03180 12.03805 12.04437 12.05077 12.05724 12.06491
## [137] 12.07479 12.08669 12.10045 12.11588 12.13281 12.15108 12.17049 12.19087
## [145] 12.21205 12.23386 12.25611 12.27863 12.30125 12.32378 12.34606 12.36790
## [153] 12.38913 12.40958 12.42907 12.44742 12.46446 12.48000 12.49389 12.50593
## [161] 12.51596 12.52533 12.53550 12.54638 12.55792 12.57004 12.58268 12.59576
## [169] 12.60923 12.62300 12.63701 12.65120 12.66549 12.67982 12.69412 12.70831
## [177] 12.72234 12.73613 12.74961 12.76272 12.77539 12.78755 12.79912 12.81005
## [185] 12.82027 12.82970 12.83828 12.84593 12.85260 12.85820 12.86269 12.86597
## [193] 12.86800 12.86869 12.86798 12.86580 12.86145 12.85442 12.84491 12.83316
## [201] 12.81938 12.80378 12.78659 12.76802 12.74829 12.72762 12.70623 12.68433
## [209] 12.66215 12.63990 12.61779 12.59606 12.57491 12.55456 12.53524 12.51716
## [217] 12.50053 12.48558 12.47253 12.45945 12.44439 12.42749 12.40893 12.38884
## [225] 12.36739 12.34474 12.32103 12.29642 12.27107 12.24513 12.21876 12.19211
## [233] 12.16534 12.13860 12.11205 12.08584 12.06013 12.03508 12.01083 11.98755
## [241] 11.96539 11.94450 11.92504 11.90716 11.89103 11.87592 11.86100 11.84627
## [249] 11.83172 11.81733 11.80310 11.78902 11.77507 11.76124 11.74753 11.73393
## [257] 11.72041 11.70698 11.69363 11.68034 11.66710 11.65390 11.64074 11.62760
## [265] 11.61446 11.60134 11.58850 11.57622 11.56448 11.55322 11.54243 11.53206
## [273] 11.52207 11.51245 11.50313 11.49411 11.48533 11.47676 11.46837 11.46013
## [281] 11.45199 11.44393 11.43590 11.42788 11.41982 11.41170 11.40348 11.39512
## [289] 11.38659 11.37803 11.36963 11.36139 11.35331 11.34540 11.33765 11.33008
## [297] 11.32269 11.31548 11.30846 11.30162 11.29499 11.28855 11.28231 11.27628
## [305] 11.27046 11.26485 11.25947 11.25430 11.24937 11.24466 11.24019 11.23596
## [313] 11.23197 11.22823 11.22474 11.22053 11.21475 11.20756 11.19914 11.18967
## [321] 11.17932 11.16826 11.15667 11.14472 11.13259 11.12045 11.10848 11.09684
## [329] 11.08572 11.07528 11.06571 11.05717 11.04985 11.04390 11.03952 11.03687
## [337] 11.03612 11.03746 11.04028 11.04385 11.04814 11.05312 11.05877 11.06505
## [345] 11.07194 11.07941 11.08743 11.09597 11.10500 11.11450 11.12444 11.13478
## [353] 11.14551 11.15658 11.16798 11.17967 11.19163 11.20382 11.21622 11.22880
## [361] 11.24154 11.25439 11.26734 11.28036 11.29477 11.31179 11.33123 11.35290
## [369] 11.37658 11.40211 11.42927 11.45787 11.48772 11.51863 11.55039 11.58282
## [377] 11.61572 11.64889 11.68215 11.71529 11.74812 11.78044 11.81207 11.84281
## [385] 11.87245 11.90082 11.92771 11.95292 11.97627 11.99756 12.01659 12.03317
## [393] 12.04900 12.06583 12.08352 12.10196 12.12102 12.14058 12.16051 12.18068
## [401] 12.20098 12.22128 12.24145 12.26137 12.28091 12.29996 12.31838 12.33605
## [409] 12.35285 12.36864 12.38332 12.39675 12.40881 12.41937 12.42831 12.43599
## [417] 12.44287 12.44899 12.45439 12.45910 12.46315 12.46659 12.46944 12.47175
## [425] 12.47354 12.47486 12.47574 12.47622 12.47632 12.47610 12.47557 12.47479
## [433] 12.47378 12.47258 12.47122 12.46975 12.46819 12.46659 12.46497 12.46338
## [441] 12.46185 12.45924 12.45454 12.44794 12.43965 12.42987 12.41880 12.40664
## [449] 12.39359 12.37986 12.36564 12.35113 12.33655 12.32208 12.30794 12.29431
## [457] 12.28141 12.26944 12.25859 12.24906 12.24107 12.23481 12.22835 12.21979
## [465] 12.20933 12.19719 12.18357 12.16869 12.15275 12.13597 12.11855 12.10071
## [473] 12.08266 12.06461 12.04676 12.02934 12.01254 11.99659 11.98168 11.96804
## [481] 11.95586 11.94537 11.93677 11.93027 11.92609 11.92327 11.92073 11.91848
## [489] 11.91650 11.91480 11.91338 11.91225 11.91140 11.91083 11.91054 11.91054
## [497] 11.91083 11.91140 11.91226 11.91341 11.91485 11.91657 11.91859 11.92089
## [505] 11.92349 11.92638 11.92956 11.93303 11.93680 11.94086 11.94522 11.95092
## [513] 11.95889 11.96895 11.98094 11.99466 12.00996 12.02664 12.04454 12.06348
## [521] 12.08328 12.10377 12.12477 12.14610 12.16759 12.18906 12.21034 12.23124
## [529] 12.25160 12.27124 12.28998 12.30765 12.32406 12.33905 12.35243 12.36404
## [537] 12.37369 12.38121 12.38642 12.39058 12.39506 12.39979 12.40476 12.40992
## [545] 12.41522 12.42063 12.42612 12.43163 12.43714 12.44260 12.44798 12.45322
## [553] 12.45830 12.46318 12.46782 12.47216 12.47619 12.47986 12.48312 12.48594
## [561] 12.48829 12.49011 12.49138 12.49205 12.49208 12.49143 12.49007 12.48795
## [569] 12.48504 12.48078 12.47472 12.46700 12.45776 12.44713 12.43525 12.42225
## [577] 12.40828 12.39347 12.37795 12.36187 12.34535 12.32854 12.31157 12.29458
## [585] 12.27770 12.26107 12.24483 12.22911 12.21405 12.19979 12.18646 12.17420
## [593] 12.16315 12.15344 12.14520 12.13642 12.12515 12.11163 12.09611 12.07882
## [601] 12.06001 12.03993 12.01881 11.99691 11.97446 11.95172 11.92891 11.90629
## [609] 11.88411 11.86259 11.84200 11.82256 11.80453 11.78815 11.77366 11.76130
## [617] 11.75133 11.74398 11.73839 11.73353 11.72936 11.72585 11.72298 11.72071
## [625] 11.71902 11.71787 11.71723 11.71708 11.71738 11.71810 11.71922 11.72070
## [633] 11.72251 11.72462 11.72701 11.72964 11.73248 11.73551 11.73869 11.74199
## [641] 11.74538 11.74884 11.75232 11.75581 11.76048 11.76740 11.77634 11.78710
## [649] 11.79945 11.81318 11.82807 11.84391 11.86049 11.87758 11.89496 11.91244
## [657] 11.92978 11.94677 11.96321 11.97886 11.99351 12.00696 12.01898 12.02936
## [665] 12.03787 12.04573 12.05422 12.06330 12.07291 12.08300 12.09352 12.10442
## [673] 12.11563 12.12712 12.13882 12.15069 12.16267 12.17471 12.18676 12.19875
## [681] 12.21065 12.22240 12.23394 12.24522 12.25620 12.26681 12.27700 12.28673
## [689] 12.29594 12.30457 12.31257 12.31990 12.32649 12.33252 12.33821 12.34357
## [697] 12.34863 12.35342 12.35796 12.36227 12.36639 12.37033 12.37412 12.37778
## [705] 12.38134 12.38481 12.38824 12.39163 12.39502 12.39843 12.40188 12.40540
## [713] 12.40901 12.41273 12.41660 12.42063 12.42460 12.42829 12.43171 12.43488
## [721] 12.43781 12.44053 12.44305 12.44538 12.44754 12.44955 12.45142 12.45317
## [729] 12.45482 12.45639 12.45788 12.45933 12.46073 12.46212 12.46350 12.46489
## [737] 12.46631 12.46778 12.46931 12.47092 12.47262 12.47444 12.47635 12.47833
## [745] 12.48036 12.48243 12.48453 12.48664 12.48875 12.49085 12.49292 12.49496
## [753] 12.49694 12.49886 12.50071 12.50246 12.50411 12.50565 12.50706 12.50832
## [761] 12.50943 12.51038 12.51114 12.51171 12.51208 12.51224 12.51222 12.51204
## [769] 12.51169 12.51120 12.51058 12.50983 12.50897 12.50802 12.50697 12.50584
## [777] 12.50465 12.50341 12.50212 12.50080 12.49947 12.49812 12.49678 12.49545
## [785] 12.49414 12.49288 12.49166 12.49050 12.48942 12.48841 12.48750 12.48663
## [793] 12.48572 12.48478 12.48381 12.48279 12.48175 12.48066 12.47954 12.47837
## [801] 12.47717 12.47593 12.47464 12.47332 12.47195 12.47054 12.46908 12.46758
## [809] 12.46603 12.46444 12.46280 12.46111 12.45938 12.45759 12.45575 12.45387
## [817] 12.45193 12.44993 12.44789 12.44579 12.44364 12.44144 12.43919 12.43690
## [825] 12.43455 12.43216 12.42972 12.42723 12.42470 12.42213 12.41951 12.41685
## [833] 12.41414 12.41140 12.40861 12.40579 12.40293 12.40002 12.39708 12.39411
## [841] 12.39109 12.38805 12.38497 12.38187 12.37874 12.37558 12.37239 12.36918
## [849] 12.36593 12.36265 12.35934 12.35600 12.35262 12.34921 12.34576 12.34227
## [857] 12.33874 12.33517 12.33157 12.32792 12.32423 12.32049 12.31671
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")